Add mixed distribution support to TrueMeasure - #615
Conversation
fjhickernell
left a comment
There was a problem hiding this comment.
Thanks for doing this Laasya.
We talked and I requested an example showing the advantage of mixture sampling over non-mixture sampling. Let me know when you have added that.
Sure!! |
There was a problem hiding this comment.
-
Remove unnecessary line breaks and add "Open in Colab" badge to the demo by running terminal command,
make format. The badge will work once this PR is merged intodevelopbranch. -
Do you plan to add mean, variance, standard deviation, and covariance to
Mixturein this PR? -
Why is weight value being 1 outside bounded support at 1.5 in the following example? Also, at any point in the bounded support, shouldn't the weight just be 0.5?
mb = Mixture(DigitalNetB2(2), [Uniform(DigitalNetB2(1), 0, 1), Uniform(DigitalNetB2(1), 2, 3)], [0.5, 0.5])
w = mb._weight(np.array([[0.5], [2.5], [1.5]])) # currently prints [1, 1, 1]
-
Should we use
rightinstead ofleftfor line 125 (self._cumulative_probabilities, flat_x[:, 0], side="left") inmixture.py? -
In
abstract_true_measure.py:84,measure.d == measure.discrete_distrib.dby construction. However, line 75 ofmixtureessentially validatesmeasure.discrete_distrib.d == measure.d + 1. The mismatch of dimensions result in exception as in the following example:
m = Mixture(DigitalNetB2(2, seed=7), [Gaussian(DigitalNetB2(1), mean=-2, covariance=1), Gaussian(DigitalNetB2(1), mean=2, covariance=1)], [0.3, 0.7])
g = CustomFun(m, lambda t: t[..., 0] ** 2)
CubQMCNetG(g).integrate()
# ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 1 and the array at index 1 has size 2
|
Thank you. I’ll run make format for the demo formatting and Colab badge. And yes, I’m planning to add mean, variance, standard_deviation, and covariance support to Mixture. |
Summary
This PR adds support for finite mixed distributions through a new
MixtureTrueMeasure.Given component distributions with densities
and probabilities
the resulting mixed distribution has density
To sample from the mixture,
Mixtureuses one additional uniform coordinate. For a component dimensiond, the outer sampler therefore has dimensiond + 1.For
the first coordinate$u_0$ selects a component according to the cumulative probabilities, and the remaining coordinates $(u_1, \ldots, u_d)$ are passed through the selected component's existing
TrueMeasuretransform. The resulting sample is in dimensiond.Implementation
MixtureTrueMeasurethat can combine different compatibleTrueMeasurecomponents.d + 1sampler dimension.TrueMeasures are preserved.Mixturethrough the publicqmcpyAPI.A new demo notebook shows the selection mechanism as well as mixtures involving different component types, including Gaussian, zero-inflated, bounded, heavy-tailed, composed, and multidimensional examples.
Tests
Added focused tests for component selection, cumulative-probability boundaries, validation, mixture weights, composed transforms, spawning, and replicated samples.